package org.xzx.shop_api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xzx.shop_api.service.UserService;
import org.xzx.shop_api.utils.JsonResult;

@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    private UserService userService;

    //登录接口
    @PostMapping("login")
    public JsonResult login(@RequestParam String username,
                            @RequestParam String password) {
        if (username == null || username.trim().isEmpty()) {
            return JsonResult.failed("用户名不能为空");
        }
        if (password == null || password.trim().isEmpty()) {
            return JsonResult.failed("密码不能为空");
        }

        String token = userService.login(username, password);
        return JsonResult.success("登录成功",token);
    }

}
